<?
//echo $_REQUEST['word'];

if (!empty($_REQUEST['word'])) $word=htmlspecialchars(strip_tags($_REQUEST['word']));
else $word="";
?>
<h1 class="title"><?=$titname;?></h1>
<br>
	<form action="/site/search/" class="otziv-form" method="post" style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
	<table>
	<tr>
		<td><input type="Text" name="word" <?if (!empty($word)) {?>value="<?=$word?>"<?}?> style="width:500px;"></td>

		<td style="padding:4px 0px 0px 10px;"><input type=submit value="Найти!" class="submit"></td>
	</tr>
	</table>
	</form>
	<br>
<?//print_r($razdel);?>

<?//print_r($razdel['news']);
?>

<?
//если слово не пришло, то искать не имеет смысла.
if (!empty($word)) {

foreach ($razdel as $razd) {
if ($razd['tablename']!="mod_settings") {
?>

<?php //Формируем запрос на поиск данных в разделе
if (strstr($razd['tablename'], "mod_")) $table=prefix.$razd['tablename'];
else $table=prefix.$razd['tablename']."_data";

$Query=" ";

//проходим все поля раздела и формируем запрос
$num=count($razd['fields']);
$i=1;
if (!empty($CatID)) unset($CatID);
if (!empty($uname)) unset($uname);

foreach ($razd['fields'] as $field) {

$Query.=" ".$field['fname']." LIKE \"%".$word."%\"";
if ($num!=$i) $Query.=" OR ";

//если у раздела есть категория или имя страницы, 
//то добавляем к запросу это хозяйство

if ($field['fname']=="CatID") $CatID=1;
if ($field['fname']=="uname") $uname=1;

$i++;
}//foreach $razd['fields'] as $field

$Que="SELECT ID, ".$razd['searchtitle'];
if (!empty($CatID)) $Que.=", CatID";
if (!empty($uname)) $Que.=", uname";
$Que.=" FROM ".$table." WHERE ";

$Query=$Que.$Query;

//смотрим, что получилось:
//echo $Query."<br><br>";

//далее выполяем запрос
$Zapros=GetQueryArray($Query);
if (!empty($Zapros)) {
//проходим запрос и кладем данные в массив
$i=0;
foreach ($Zapros as $Zap) {

$rezult[$i]['title']=$Zap[$razd['searchtitle']];
$rezult[$i]['ID']=$Zap['ID'];
$rezult[$i]['rname']=$razd['name'];
$rezult[$i]['tablename']=$razd['tablename'];
if (!empty($Zap['uname'])) $rezult[$i]['uname']=$Zap['uname'];
if (!empty($Zap['CatID'])) $rezult[$i]['caturl']=GetCategoryUrl($razd['tablename'], $Zap['CatID']);
if (!empty($Zap['CatID'])) $rezult[$i]['CatID']=$Zap['CatID'];
if (!empty($Zap['CatID'])) $rezult[$i]['catname']=GetCatName($razd['tablename'], $Zap['CatID']);

$i++;
}//foreach $Zapros

//print_r($rezult);

if (empty($global_result)) $global_result=$rezult;
else $global_result=array_merge($global_result, $rezult);

}//if if (!empty($Zapros)) {
?>

<?
}//if ($razd['tablename']!="mod_settings") {
}//foreach $razdel
}//if (!empty($word)) {
else echo "Введите слово, которое вы хотите найти.";
?>
<?
//выводим результаты поиска
if (!empty($global_result)) {

$num=count($global_result);

if ($num==1) $colvo="совпадение";
else if ($num<5) $colvo="совпадения";
else if ($num>=5) $colvo="совпадений";

echo "По запросу <u><strong>".$word."</strong></u> найдено ".$num." ".$colvo.":<br><br>";

///////////////////////////
//Кладем запрос в базу...
/*
$param="";

if (!empty($word)) { 
	//$zapros_into_base=$word;
	$param['sword']=$word;
}//if

if (!empty($global_result)) { 
	//$result_into_base=array_to_string($global_result);
	$param['sresult']=array_to_string($global_result);
}//if (!empty($global_result)) {

//$ip_into_base=$ip;
$param['sip']=$ip;

//$date_ino_base=dt2ut($this_time);
$param['sdate']=dt2ut($this_time);

//$referer_into_base=$_SERVER['HTTP_REFERER'];
$param['sreferer']=$_SERVER['HTTP_REFERER'];

$stable=prefix."searchrez_data";

$do_insert=AddQuery ($param, $stable);
*/
//echo "<br>".$result_into_base."<br>";
/*
echo "<pre>";
print_r(string_to_array($result_into_base));
echo "</pre>";


echo "<pre>";
print_r($global_result);
echo "</pre>";
*/

//\Кладем запрос в базу...
///////////////////////////





foreach ($global_result as $result) {
if (!empty($result['uname'])) $NewURL=$result['uname'];
else $NewURL=translist($result['title']);

if ($result['tablename']=="news") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/news/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/news/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  


if ($result['tablename']=="priemnaya") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/priemnaya/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/priemnaya/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;">Вопрос от <?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  


if ($result['tablename']=="docs") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/docs/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/docs/c-<?=$result['caturl']?>/#file-<?=$result['ID']?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  

/*
if ($result['tablename']=="aqua") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/aquariums/others/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<?if (!empty($result['catname'])) {?><a href="/aquariums/others/c-<?=$result['caturl']?>/" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['catname']."</a> &mdash; "; }?>
	<a href="/aquariums/others/<?=$result['ID'].".html/";?>" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  
if ($result['tablename']=="aquastand") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/aquariums/aquastand/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/aquariums/aquastand/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  
if ($result['tablename']=="equipment") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/equipment/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<?if (!empty($result['catname'])) {?><a href="/equipment/<?=$result['caturl']?>/" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['catname']."</a> &mdash; "; }?>
	<a href="/equipment/<?=$result['caturl']?>/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  
if ($result['tablename']=="servises") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/aquariums/servises/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/aquariums/servises/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") {  
if ($result['tablename']=="specpr") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/aquariums/specpr/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/aquariums/specpr/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") { 
if ($result['tablename']=="talk") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/talk/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/talk/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") { 
if ($result['tablename']=="portfolio") {  
	//$url="/presscenter/news/".$NewURL.".html";
	?>
	<span style="font-size:12px;">
	<a href="/aquariums/portfolio/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?=$result['rname'];?></a> &mdash;
	<a href="/aquariums/portfolio/<?=$result['ID'].".html/";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
}//if ($result['tablename']=="aqua") { portfolio
*/

if ($result['tablename']=="html") {  

	//if ($result['caturl']=="all-pages") {
	/* and 
	($NewURL=="about" or 
	$NewURL="vacancy" or 
	$NewURL="tech-solutions" or 
	$NewURL="contacts")
	*/
	//if ($NewURL=="catalog") $murl="catalog";
	//elseif ($NewURL=="price-list") $murl="price";
	//else $murl="company";
	
	$murl="";
	?>
	<span style="font-size:12px;">
	<a href="<?php echo $murl;?>/" target="_blank" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;"><?php echo site_name;?></a> &mdash;
	<a href="<?php echo $murl;?>/<?=$NewURL.".html";?>" target="_blank" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
	//}//$result['caturl']=="all-pages"
	/*
	if ($result['caturl']=="build-top" or $result['caturl']=="build-bot")
	{
	?>
	<span style="font-size:12px;">
	<a href="/servise/creation/" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;">Услуги и цены</a> &mdash;
	<a href="/servise/creation/" style="font-size:12px; font-weight: bold;">Создание</a> &mdash;
	<a href="/servise/creation/<?=$NewURL.".html";?>" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
	}//$result['caturl']=="all-pages"
	
	if ($result['caturl']=="advertising")
	{
	?>
	<span style="font-size:12px;">
	<a href="/servise/advertising/" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;">Услуги и цены</a> &mdash;
	<a href="/servise/advertising/" style="font-size:12px; font-weight: bold;">Реклама</a> &mdash;
	<a href="/servise/advertising/<?=$NewURL.".html";?>" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
	}//$result['caturl']=="all-pages"
	
	if ($result['caturl']=="support")
	{
	?>
	<span style="font-size:12px;">
	<a href="/servise/" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;">Услуги и цены</a> &mdash;
	<a href="/servise/support/" style="font-size:12px; font-weight: bold;">Поддержка</a> &mdash;
	<a href="/servise/support/<?=$NewURL.".html";?>" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
	}//$result['caturl']=="all-pages"
	
	if ($result['caturl']=="hosting")
	{
	?>
	<span style="font-size:12px;">
	<a href="/servise/" style="color:#737373; font-size:12px; font-weight: bold; text-decoration: none;">Услуги и цены</a> &mdash;
	<a href="/servise/hosting/" style="font-size:12px; font-weight: bold;">Хостинг</a> &mdash;
	<a href="/servise/hosting/<?=$NewURL.".html";?>" style="font-size:12px; font-weight: normal;"><?=$result['title'];?></a>
	</span><br><br>
	<?
	}//$result['caturl']=="all-pages"
*/
	
}//if ($result['tablename']=="news") {  

//if ($result['tablename']=="faq") $url="/r-".$result['tablename']."/#".$result['ID'];
//if ($result['tablename']=="autopark") $url="/r-".$result['tablename']."/c-".$result['caturl']."/";
?>

<?
}//foreach

}//if !empty($global_result)
else echo "По вашему запросу <u><strong>".$word."</strong></u> ничего не найдено. Попробуйте уточнить запрос.<br><br>";
?>